//
//  ServiceCategoriesViewController.swift
//  
//
//  Created by Ralf on 6/12/15.
//
//

import UIKit

class ServiceCategoriesViewController: ViewController
{
    let appDelegate                                        = UIApplication.sharedApplication().delegate as! AppDelegate
    let firstDelegate                                      = ServiceCategoriesL1Delegate()
    let secondDelegate                                     = ServiceCategoriesL2Delegate()
    let firstLayout:            UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    let secondLayout:           UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    var activityViewController:MarketViewController!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.yellowColor()

//        firstLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
//        firstLayout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.size.width * 0.2, height: 100.0)
//        firstLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
//        firstLayout.minimumLineSpacing = 1
//        firstLayout.minimumInteritemSpacing = 3
//        var firstCollectionController = UICollectionView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 100), collectionViewLayout: firstLayout)
//        firstCollectionController.backgroundColor = UIColor.whiteColor()
//
//        firstCollectionController.delegate = firstDelegate
//        firstCollectionController.dataSource = firstDelegate
//        firstCollectionController.registerNib(UINib(nibName: "FirstCategoryCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "FirstCell")
//        self.view.addSubview(firstCollectionController)
        
        firstLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        firstLayout.itemSize = CGSize(width: 60, height: 60.0)
        firstLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
        firstLayout.minimumLineSpacing = 1
        firstLayout.minimumInteritemSpacing = 3
        let firstCollectionController = UICollectionView(frame: CGRectMake(0,0,60,600), collectionViewLayout: firstLayout)
        firstCollectionController.backgroundColor = UIColor.groupTableViewBackgroundColor()

        firstCollectionController.delegate = firstDelegate
        firstCollectionController.dataSource = firstDelegate
        firstCollectionController.registerNib(UINib(nibName: "FirstCategoryCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "FirstCell")
        self.view.addSubview(firstCollectionController)
        
//        secondLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
//        secondLayout.itemSize = CGSize(width: UIScreen.mainScreen().bounds.size.width * 0.3, height: 120.0)
//        secondLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
//        secondLayout.minimumLineSpacing = 1
//        secondLayout.minimumInteritemSpacing = 3
//
//        secondDelegate.activityViewController = activityViewController
//        var secondCollectionController
//        = UICollectionView(frame: CGRectMake(0, 100, UIScreen.mainScreen().bounds.size.width, 400), collectionViewLayout: secondLayout)
//        secondCollectionController.backgroundColor = UIColor.whiteColor()
//        secondCollectionController.delegate = secondDelegate
//        secondCollectionController.dataSource = secondDelegate
//        secondCollectionController.registerNib(UINib(nibName: "SecondCategoryCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SecondCell")
//        self.view.addSubview(secondCollectionController)
        secondLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        secondLayout.itemSize = CGSize(width:81, height: 110.0)
        secondLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
        secondLayout.minimumLineSpacing = 1
        secondLayout.minimumInteritemSpacing = 1
        secondDelegate.activityViewController = activityViewController
        let secondCollectionController = UICollectionView(frame: CGRectMake(60, 0, 260,600), collectionViewLayout: secondLayout)
        secondCollectionController.backgroundColor = UIColor.whiteColor()
        secondCollectionController.delegate = secondDelegate
        secondCollectionController.dataSource = secondDelegate
        secondCollectionController.registerNib(UINib(nibName: "SecondCategoryCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SecondCell")
        
        self.view.addSubview(secondCollectionController)

        firstDelegate.secondview = secondCollectionController
        firstDelegate.secondDelegate = secondDelegate

        self.navigationItem.title = "分类"

        initBackButton()
    }

    override func viewWillAppear(animated: Bool)
    {

    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
